package club.xinghe.servlet.teacher;

import club.xinghe.biz.ExamBiz;
import club.xinghe.util.JsonServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/teacher/QRaddServlet")
public class QRaddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int teacherid = Integer.parseInt(request.getParameter("teacherid"));
        int zid = Integer.parseInt(request.getParameter("zid"));
        String examname = request.getParameter("examname");
        String estring = request.getParameter("estring");
        String estart = request.getParameter("estart");
        String eend = request.getParameter("eend");
        int etime = Integer.parseInt(request.getParameter("etime"));
        int yid = Integer.parseInt(request.getParameter("yid"));
        int gid = Integer.parseInt(request.getParameter("gid"));

        String[] e1 = estart.split("T");
        String[] e2 = eend.split("T");

        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();

        String e = ":00";

        String ee1 = "";
        for (int i = 0; i < e1.length ; i++) {
            list1.add(e1[i]);
        }
        for (String tt:list1
             ) {
            ee1 += tt+" ";
        }
        ee1 = ee1.trim();
        ee1 += e;

        String ee2 = "";
        for (int i = 0; i < e2.length ; i++) {
            list2.add(e2[i]);
        }
        for (String tt:list2
             ) {
            ee2 += tt+" ";
        }
        ee2 = ee2.trim();
        ee2 += e;


        Map map = new HashMap();
        map.put("teacherid",teacherid);
        map.put("zid",zid);
        map.put("examname",examname);
        map.put("estring",estring);
        map.put("estart",ee1);
        map.put("eend",ee2);
        map.put("etime",etime);
        map.put("yid",yid);
        map.put("gid",gid);
        ExamBiz examBiz = new ExamBiz();
        int n = examBiz.addExam(map);
        PrintWriter out=response.getWriter();
        out.print(n);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
